<template>
  <div class="container">
    <div class="about" v-for="item in shoplist" :key="item.id" :data-shopid="item.id" :data-name="item.name" @tap="goDataAnalysis" v-if="!showList">
      <div class="version shop flex">
        <span class="flex-item">{{item.name}}</span>
        <span class="ver_words">
          <i class="grey_arrow"></i>
        </span>
      </div>
    </div>
    <van-cell-group class="cell-group" v-if="showList">
      <van-cell :title="item.name" :value="item.details" is-link arrow-direction="right" v-for="item in expandingList" :key="item.id" @click="goDetails(item.id)" />
    </van-cell-group>
  </div>
</template>

<script>
import api from '@/utils/api'
import wx from 'wx'
import Toast from '@/utils/toast'
export default {
  data () {
    return {
      shoplist: [],
      expandingList: [],
      shopid: 0,
      showList: false
    }
  },
  components: {
  },
  onShow () {
    this.showList = false
  },
  async onLoad () {
    this.getmyjsonshoplist()
  },
  methods: {
    async getmyjsonshoplist () {
      let userInfo = wx.getStorageSync('userInfo')
      const res = await api.getmyjsonshoplist({ jsonshop: userInfo.jsonshop });
      if (res) {
        if (res.code === '100') {
          this.shoplist = res.data
        } else {
          Toast(res.msg)
        }
      } else {
        Toast('接口错误！');
      }
    },
    async getinfo (shopid) {
      let userId = wx.getStorageSync('userInfo').user_id;
      let ret = await api.expandingCustomers({ user_id: userId, shop_id: shopid });
      if (ret.code === '100') {
        ret.data.forEach(item => {
          item.details = `￥${item.price}`
        })
        this.expandingList = ret.data
        this.showList = true
      } else {
        this.expandingList = []
        Toast(ret.msg)
      }
    },
    goDataAnalysis (e) {
      console.log(e.mp.currentTarget.dataset.shopid)
      let shopid = e.mp.currentTarget.dataset.shopid
      this.shopid = shopid
      this.getinfo(shopid)
    },
    goDetails (id) {
      wx.navigateTo({
        url: '/pages/guest/expandingCustomersDetails/expandingCustomersDetails?shareid=' + id + '&shopid=' + this.shopid
      })
    }
  }
}
</script>

<style scoped>
.container {
  padding-top: 16rpx;
}
.about {
  width: 100%;
  background: #fff url("http://mytimg.178mr.com/aboutmyt@3x.png") no-repeat;
  background-position: 44rpx 28rpx;
  background-size: 32rpx 32rpx;
  padding-left: 108rpx;
  padding-right: 44rpx;
  border-bottom: 2rpx solid RGBA(153, 153, 153, 0.1);
}
.version {
  width: 100%;
  height: 84rpx;
  font-size: 32rpx;
  font-weight: 400;
  line-height: 84rpx;
  color: rgba(51, 51, 51, 1);
}
.ver_words {
  font-size: 28rpx;
  color: rgba(153, 153, 153, 1);
}
.grey_arrow {
  display: inline-block;
  width: 12rpx;
  height: 28rpx;
  background: url(http://mytimg.178mr.com/grey_arrow.png) no-repeat;
  background-size: 100%;
  position: relative;
  top: 6rpx;
  margin-left: 30rpx;
}
.ul {
  width: 100%;
}
.li {
  float: left;
  position: relative;
  box-shadow: 0px 6rpx 20rpx rgba(255, 68, 68, 0.1);
  background-color: #fff;
  border-radius: 10rpx;
  margin: 18rpx 0 0 16rpx;
  font-size: 28rpx;
  color: rgba(102, 102, 102, 1);
}
.li span {
  padding: 10rpx 60rpx;
}
.li .close {
  position: absolute;
  top: 4rpx;
  right: 10rpx;
}
.send {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 110rpx;
  background-color: #fff;
}
.send .input {
  width: 582rpx;
  height: 64rpx;
  padding-left: 32rpx;
  font-size: 28rpx;
  border-radius: 30rpx;
  background-color: rgba(153, 153, 153, 0.1);
  margin-left: 48rpx;
}
.send .input input {
  width: 100%;
  height: 100%;
  border-radius: 30rpx;
}
.send .button {
  font-size: 32rpx;
  color: rgba(102, 102, 102, 1);
  height: 100%;
}
.cell-group {
  width: 100%;
}
</style>
<style>
.van-cell__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
